package model

import (
	"gorm.io/gorm"
	"member_srv/basic/config"
	"time"
)

type Protobuf struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	VideoId   int32          `gorm:"column:video_id;type:int;not null;" json:"video_id"`
	UserId    int32          `gorm:"column:user_id;type:int;not null;" json:"user_id"`
	Status    int8           `gorm:"column:status;type:tinyint(1);not null;" json:"status"`
	Content   string         `gorm:"column:content;type:varchar(30);not null;" json:"content"`
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (p *Protobuf) TableName() string {
	return "protobuf"
}

func (p *Protobuf) AddProtobuf() error {
	return config.DB.Create(&p).Error
}

func (p *Protobuf) FindProtobuf() error {
	return config.DB.Where("video_id = ?", p.VideoId).Find(&p).Error
}

func (p *Protobuf) UpdateProtobuf() error {
	return config.DB.Updates(&p).Error
}
